package com.example.jones.test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.constant.AppConstant;
import com.example.constant.VariableKey;
import com.example.util.HttpUtil;
import com.example.util.HttpUtilWithParameter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class MyColletion extends Activity {
    private ListView mycollection;
    private List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    private SimpleAdapter simpleAdapte;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.id.mycollectionlistview);
        mycollection = (ListView) findViewById(R.id.mycollectionlistview);
        Adapter();
        mycollection.setAdapter(simpleAdapte);
        mycollection.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Intent it=new Intent(MyColletion.this,DtlActivity.class);
                it.putExtra("cbID", list.get(position).get("cbID"));                    
                it.putExtra("dishImage", list.get(position).get("dishImage"));                    
                it.putExtra("dishName", list.get(position).get("dishName"));  
                startActivity(it);
            }

        });
    }

    public void Adapter() {
        String result = HttpUtilWithParameter.Getcollection(HttpUtil.Base_url
                + "/MyCollectionService",
                (String) AppConstant.GLOBAL_VARIABLE.get(VariableKey.USER_ID));
        Gson gson = new Gson();
        list = gson.fromJson(result,
                new TypeToken<List<Map<String, String>>>() {
                }.getType());
        simpleAdapte = new SimpleAdapter(this, list,
                R.layout.listview_mycollection, new String[] { "dishName",
                        "dishInfo", "dishHits", "shareNum" }, new int[] {
                        R.id.dishname, R.id.dishinfo, R.id.dishhit,
                        R.id.sharenum });
    }
}
